<template>
	<div>
		<Layout>
			<Content class="layout-content">
				<Row>
					<Col span="24">
						<!--            <div id="jsoneditor" ref="jsonEditor" style="width: 100%; height: 600px;"></div>-->
						<ParamMapping
							v-if="props.componentConfig?.input && props.componentConfig?.output"
							:leftData="props.componentConfig?.input"
							:rightData="props.componentConfig?.output"
							ref="left"
						></ParamMapping>
					</Col>
				</Row>
			</Content>
		</Layout>
	</div>
</template>
<script setup>
import { onMounted, ref, watch, toRaw, inject, getCurrentInstance } from 'vue'
import { Message, Radio, Row, Switch } from 'view-ui-plus'
import ParamMapping from '@/views/restapi/ParamMapping.vue'
import processVersionContentApi from '@/api/process/processVersionContentApi'

const defaultConfig = () => {
	return {
		input: {
			params: [],
			basicTypeFlag: false,
			isArrayFlag: false,
			isActionColumnFlag: false,
			isMappingColumnFlag: false,
			isAddColumnFlag:false,
			isUpdateColumnFlag:false,
			jsonEditorFlag: false
		},
		output: {
			params: [],
			basicTypeFlag: false,
			isArrayFlag: false,
			isActionColumnFlag: true,
			isMappingColumnFlag: true,
			isViewAutoMappingFlag: true,
			isUpdateColumnFlag:true,
			isClearFlag: true,
			jsonEditorFlag: true
		}
	}
}

const props = defineProps(['componentConfig', 'id', 'nodeId', 'frontFile'])

// const isArrayFlag = ref(false);
const left = ref()

onMounted(() => {
	if (!hasProperties(props.componentConfig)) {
		const c = defaultConfig()
		props.componentConfig.input = c.input
		props.componentConfig.output = c.output
	}

	queryInput()
})

const hasProperties = (obj) => {
	if (!obj) {
		return false
	}

	return JSON.stringify(obj) != '{}'
}

const queryInput = async () => {
	const c = await getInputDefine()
	if (c) {
		const cb = left.value.repairJson(c)
		props.componentConfig.input = cb
	}
}
const getInputDefine = async () => {
	// const versionId = props.input.versionId
	// let resource = props.input.resource

	//需要调用后端查询接口定义
	const read = await processVersionContentApi.getCurrentInputDefine({
		id: props.id,
		frontFile: props.frontFile,
		stepCode: props.nodeId
	})
	return read
}
</script>
<style scoped></style>
